// 
//  Test_UserInfo.cs
//  
//  Author:
//       Ray Shaw <demogodyou@gmail.com>
// 
//  Copyright (c) 2009 Ray Shaw(xiaolei)
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:2.0.50727.3053
//
//     对此文件的更改可能会导致不正确的行为，并且如果
//     重新生成代码，这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Data;
using SharpNote.Core.Config;
using SharpNote.Core.Data;
using SharpNote.Core.Entity;
using SharpNote.Core.Security;


namespace Test
{


	public class Test_UserInfo: ITestCase
	{

		public Test_UserInfo ()
		{

		}

		public bool Test ()
		{
			bool ok = false;
			
			SysConfig sysConfig = SysConfig.GetInstance ();
			sysConfig.DbFileName = System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "SharpNote.db");
			sysConfig.DbPassword = "";

			DateTime startTime = DateTime.Now;
			Console.WriteLine (string.Format ("Test start time: {0}.", startTime.ToString ("yyyy-MM-dd HH:mm:ss fff")));
			int successCount = 0;
			int failCount = 0;
			string password = "test123~";

			for (int i = 0; i < 10; i++) {
				UserInfo userInfo = new UserInfo ();
				userInfo.UserName = "test_" + Guid.NewGuid ().ToString ();
				userInfo.SetSignInPassword(password);
				userInfo.SetPrivateKey(Guid.NewGuid().ToString(), password);
				//userInfo.SetDbPassword(password, "I am dbPassword.");
				userInfo.SetDefaultKey(password, "I am globalPassword.");
				Guid newGuid = Guid.NewGuid();
				byte[] keyBytes = newGuid.ToByteArray ();
				string privateKey = newGuid.ToString();
				
				bool result = DbObjectMappingHelper.Create<UserInfo> (userInfo);
				if (result) {
					successCount++;
				} else {
					failCount++;
				}

				Console.WriteLine (string.Format ("{0}. Create new user: {1}.", i + 1, result));
				
				string plainPassword = password;
				Console.WriteLine(string.Format("   Test plain text: \"{0}\" is equals the true password: \"{1}\": {2}.", 
				                                plainPassword,
				                                password,
				                                userInfo.IsSignInPasswordEquals(plainPassword)));
			}

			Console.WriteLine (string.Format ("Test completed. Spent millionseconds: {0}, success: {1}, fail: {2}.", DateTime.Now.Subtract (startTime).TotalMilliseconds, successCount, failCount));

			ok = failCount == 0;
			return ok;
		}
	}
}
